package cn.changsha.xczxapp.ffmpeg;

/**
 * FFmpeg native 层的 bridge
 *
 * Created by Liuhailong on 2018/1/3 15:31
 * e-mail:419977897@qq.com
 *
 */

public class FFmpegNativeBridge {

    static {
        System.loadLibrary("avcodec");
        System.loadLibrary("avdevice");
        System.loadLibrary("avfilter");
        System.loadLibrary("avformat");
        System.loadLibrary("avutil");
        System.loadLibrary("swresample");
        System.loadLibrary("swscale");
        System.loadLibrary("xctt-lib");
    }

    private static FFmpegProgressListener listener;
    public static void onProgress(int second) {
        if (listener != null && second >= 0) {
            listener.onProgress(second);
        }
    }

    public static int runCommand(String[] command){
        int ret;
        synchronized (FFmpegNativeBridge.class){
            // 不允许多线程访问
            ret = ffmpegExec(false, command);
        }
        return ret;
    }

    public static int run(boolean isDebug, String[]command, FFmpegProgressListener callBack) {
        int ret = 1;
        listener = callBack;
        synchronized (FFmpegNativeBridge.class){
            // 不允许多线程访问
            ret = ffmpegExec(isDebug, command);
        }
        return ret;
    }

    public native static String getCheckCode(String code);
    public native static String getFFmpegVersion();
    public native static int ffmpegExec(boolean isDebug, String[]command);
}
